package com.jml.代理模式.五期.注解失效.service.impl;

import com.jml.代理模式.五期.注解失效.service.MemberService;
import com.jml.代理模式.五期.注解失效.service.manage.MemberServiceManage;
import com.jml.代理模式.五期.注解失效.service.utils.SpringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;


import lombok.extern.slf4j.Slf4j;



//使用jdk代理对象调用@Async注解，让注解有效，让controller有效。

@Component
@Slf4j
public class MemberServiceImpl  implements MemberService {

    @Autowired
    private MemberServiceManage memberServiceManage;


    public String addUser() {
        log.info(">>>流程1");
        //直接从spring容器中获取
        MemberService memberServiceImplProxy = SpringUtils.getBean("memberServiceImpl");
        memberServiceImplProxy.addUserLog();

        //单独放在一个类中，这也是从容器中获取代理类
        //memberServiceManage.addUserLog();

        //直接调用注解失效
        //addUserLog();
        log.info(">>>流程3");
        return "success";
    }

    @Async()
    public String addUserLog() {
        try {
            Thread.sleep(1000);
        } catch (Exception e) {

        }
        log.info(">>>流程2");
        return "success";
    }

    /**
     *
     * 公开课 手写异步直接 @Async() 分析/    public String addUserLog() {
     */
}
